package com.bachelor.community.service.impl;

import com.bachelor.community.mapper.VoteMapper;
import com.bachelor.community.model.entity.Vote;
import com.bachelor.community.service.intf.VoteService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class VoteServiceImpl extends ServiceImpl<VoteMapper, Vote> implements VoteService {
    @Resource
    private VoteMapper voteMapper;

    @Override
    public Vote checkUserVoteState(Integer voter, Integer entityId, Integer entityType) {
        QueryWrapper<Vote> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("voter", voter);
        queryWrapper.eq("entity_id", entityId);
        queryWrapper.eq("entity_type", entityType);
        return voteMapper.selectOne(queryWrapper);
    }
}
